package com.spring.sso.common;

import lombok.Data;

/**
 * @author : pangfuzhong
 * @description
 * @date : 2021/9/16 11:19
 */
@Data
public class CommonResult<T> {

    private Boolean success;

    private String errorCode;

    private String message;

    private T data;

    public CommonResult() {

    }

    public CommonResult(T data) {
        this.success = Boolean.TRUE;
        this.errorCode = "1";
        this.message = "处理成功";
        this.data = data;
    }

    public static CommonResult success(Object data) {
        return new CommonResult(data);
    }

    public static CommonResult success(String message, Object data) {
        CommonResult commonResult = new CommonResult();
        commonResult.setSuccess(Boolean.TRUE);
        commonResult.setErrorCode("0");
        commonResult.setMessage(message);
        commonResult.setData(data);
        return commonResult;
    }

    public static CommonResult failed(String errorCode, String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setSuccess(Boolean.FALSE);
        commonResult.setErrorCode(errorCode);
        commonResult.setMessage(message);
        commonResult.setData(null);
        return commonResult;
    }
}
